package com.peng.ivos.dictoption.controller;

import com.peng.ivos.base.response.JsonResult;
import com.peng.ivos.dictoption.pojo.dto.DictOptionQuery;
import com.peng.ivos.dictoption.pojo.dto.DictOptionSaveParam;
import com.peng.ivos.dictoption.service.DictOptionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 字典项控制层
 * @author： Peng
 * @date： 2024/5/27
 * @version: 1.0
 */
@RestController
@RequestMapping("/v1/dictoption")
@Slf4j
public class DictOptionController {
    @Autowired
    private DictOptionService dictOptionService;

    @GetMapping("/select")
    public JsonResult getDictOptionList(DictOptionQuery dictOptionQuery){
        log.debug("字典项列表查询参数, dictOptionQuery: {}", dictOptionQuery);
        return dictOptionService.getDictOptionList(dictOptionQuery);
    }

    @PostMapping("/save")
    public JsonResult saveDictOption(DictOptionSaveParam dictOptionSaveParam){
        log.debug("字典项保存参数, dictOptionSaveParam: {}", dictOptionSaveParam);
        dictOptionService.saveDictOption(dictOptionSaveParam);
        return JsonResult.success("保存字典项成功");
    }

    @PostMapping("/delete/{id}")
    public JsonResult deleteDictOption(@PathVariable("id") Long id){
        log.debug("字典项删除参数, id: {}", id);
        return dictOptionService.deleteDictOption(id);
    }

    @GetMapping("/select/{code}")
    public JsonResult selectDictOptionByCode(@PathVariable("code") String code){
        log.debug("根据字典编码查询字典项查询参数, code: {}", code);
        return dictOptionService.selectDictOptionByCode(code);
    }

}
